<?php

namespace App\Models\Chanjet;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class TplusInboundAdjustmentOrder extends Model
{
    protected $table = 'tplus_inbound_adjustment_order';
    public $timestamps = false;
    protected $primaryKey = 'id';
    protected $guarded = ['_token'];

    public static function getList(Request $request, $memberinfo, $isgetall)
    {
        $cpid = $memberinfo['cpid'] ?? 0;
        $where[] = ['cpid',$cpid];
        if($request->voucher_code){
            $where[] = ['voucher_code',$request->voucher_code];
        }
        $query = self::with("info")->where($where)->orderBy('voucher_time','desc');

        if ($isgetall == 0) {
            $limit = $request->limit ?? 10;
            $list = $query->paginate($limit)->toArray();
            return paginateDataToArray($list);
        } else {
            $list = $query->get()->toArray();
            return ['list' => $list];
        }

    }
    public function info()
    {
        return $this->hasMany(TplusInboundAdjustmentOrderInfo::class,'main_id','id');
    }
}
